package com.xbs.dao.hitchhiking;
/**
 * 顺风车dao
 * @author dell
 */

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.xbs.dao.conn.BaseDao;
import com.xbs.dao.conn.ParamSet;
import com.xbs.dao.conn.RowDatas;
import com.xbs.entity.CarModelEntity;
import com.xbs.entity.CityEntity;
import com.xbs.entity.HitchEntity;
import com.xbs.entity.HitchhikeEntity;
import com.xbs.entity.StoreEntity;
/**
 * 顺风车辆管理dao层
 * @author dell
 */
public class HitchCarAdminDao extends BaseDao{

	private RowDatas<HitchEntity> hitchentity;//创建一个对象
	
	public HitchCarAdminDao(){
		hitchentity = new HitchData();
	}
	
	/**
	 * 1.查询所有顺风车辆信息
	 */
	public List<HitchEntity> getAllCar(){
		String sql = "select hc.hitch_id,hc.hitch_status,"
				+ " date_format(hc.hitch_time,'%Y-%m-%d') as hitch_time,"
				+ " date_format(hc.hitch_return_time,'%Y-%m-%d') as return_time,"
				+ " hc.hitch_day,hc.hitch_money,"
				+ " hc.hitch_miles,cm.car_model_name,s.store_name,s.store_city,"
				+ " s2.store_name as store_name1,s2.store_city as store_city1"
				+ " from tb_hitchhiking hc left join tb_car c "
				+ " on hc.hitch_id = c.car_id "
				+ " left join tb_car_model cm on c.car_model_id = cm.car_model_id"
				+ " left join tb_store s on s.store_id = hc.hitch_num "
				+ " left join tb_store s2 on s2.store_id = hc.hitch_return_num ";

		return queryList(sql, hitchentity);
	}
	
	/**
	 * 2.向顺风车表中天际爱一辆顺风车
	 * @author dell
	 */
	public List<HitchEntity> insertCar(){
		String sql = "";
		return queryList(sql, new ParamSet(),hitchentity);
	}
	
	
	
	
	class HitchData implements RowDatas<HitchEntity>{

		@Override
		public HitchEntity getRowData(ResultSet rs) throws SQLException {
			HitchEntity hitch = new HitchEntity();
			hitch.setHitch_id(rs.getString("hitch_id"));
			hitch.setHitch_day(rs.getInt("hitch_day"));
			hitch.setHitch_miles(rs.getDouble("hitch_miles"));
			hitch.setHitch_money(rs.getDouble("hitch_money"));
//			hitch.setHitch_num(rs.getInt("hitch_num"));
			hitch.setEnd_store_city(rs.getString("store_city"));
			hitch.setEnd_store_name(rs.getString("store_name"));
			hitch.setStart_store_city(rs.getString("store_city1"));
			hitch.setStart_store_name(rs.getString("store_name1"));
/*			hitch.setHitch_return_num(rs.getInt("hitch_return_num"));*/
			hitch.setHitch_status(rs.getString("hitch_status"));
			hitch.setHitch_time(rs.getDate("hitch_time"));
			hitch.setHitch_return_time(rs.getDate("return_time"));
			hitch.setCarmodelname(rs.getString("car_model_name"));
			return hitch;
		}
		
	}

}
